package com.ruoyi.monitor.infoprojectmonitorfunds.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.monitor.infoprojectmonitorfunds.domain.InfoProjectMonitorFunds;
import com.ruoyi.monitor.infoprojectmonitorfunds.service.IInfoProjectMonitorFundsService;
import com.ruoyi.monitor.infoprojectmonitorfunds.vo.InfoProjectMonitorFundsVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目监控资金监控详情  Controller
 *
 * @author ruoyi
 * @date 2022-02-15
 */
@RestController
@RequestMapping("/infoProjectMonitorFunds/infoProjectMonitorFunds")
public class InfoProjectMonitorFundsController extends BaseController {
    @Autowired
    private IInfoProjectMonitorFundsService infoProjectMonitorFundsService;

    /**
     * 查询项目监控资金监控详情  列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoProjectMonitorFunds infoProjectMonitorFunds) {
        startPage();
        List<InfoProjectMonitorFunds> list = infoProjectMonitorFundsService.selectInfoProjectMonitorFundsList(infoProjectMonitorFunds);
        return getDataTable(list);
    }

    /**
     * 导出项目监控资金监控详情  列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:export')")
    @Log(title = "项目监控资金监控详情  ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoProjectMonitorFunds infoProjectMonitorFunds) {
        List<InfoProjectMonitorFunds> list = infoProjectMonitorFundsService.selectInfoProjectMonitorFundsList(infoProjectMonitorFunds);
        ExcelUtil<InfoProjectMonitorFunds> util = new ExcelUtil<InfoProjectMonitorFunds>(InfoProjectMonitorFunds.class);
        util.exportExcel(response, list, "项目监控资金监控详情  数据");
    }

    /**
     * 获取项目监控资金监控详情  详细信息
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoProjectMonitorFundsService.selectInfoProjectMonitorFundsById(id));
    }

    /**
     * 新增项目监控资金监控详情
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:add')")
    @Log(title = "项目监控资金监控详情  ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoProjectMonitorFunds infoProjectMonitorFunds) {
        return toAjax(infoProjectMonitorFundsService.insertInfoProjectMonitorFunds(infoProjectMonitorFunds));
    }

    /**
     * 修改项目监控资金监控详情
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:edit')")
    @Log(title = "项目监控资金监控详情  ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoProjectMonitorFunds infoProjectMonitorFunds) {
        return toAjax(infoProjectMonitorFundsService.updateInfoProjectMonitorFunds(infoProjectMonitorFunds));
    }

    /**
     * 删除项目监控资金监控详情
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorFunds:infoProjectMonitorFunds:remove')")
    @Log(title = "项目监控资金监控详情  ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoProjectMonitorFundsService.deleteInfoProjectMonitorFundsByIds(ids));
    }


    /**
     * 根据关系表的id查询该执行期的执行数
     *
     * @param relationMonitorId
     * @return
     */
    @RequestMapping(value = "/getProjectMonitorFundsByRelMonId", method = RequestMethod.GET)
    public AjaxResult getInfoProjectMonitorFundsByRelationMonitorId(@RequestParam("relationMonitorId") Long relationMonitorId) {
        InfoProjectMonitorFunds infoProjectMonitorFunds = new InfoProjectMonitorFunds();
        infoProjectMonitorFunds.setProjectMonitorRelationId(relationMonitorId);
        List<InfoProjectMonitorFunds> infoProjectMonitorFunds1 = infoProjectMonitorFundsService.selectInfoProjectMonitorFundsList(infoProjectMonitorFunds);
        if (infoProjectMonitorFunds1.isEmpty()) {
            throw new RuntimeException("该执行期项目资金为空");
        }
        return AjaxResult.success(infoProjectMonitorFunds1.get(0));
    }

    /**
     * 查询所有执行率及项目名称
     * @return
     */
    @ApiOperation("查询所有执行率")
    @RequestMapping(value = "/findMonitorFundsAndProjectNames",method = RequestMethod.GET)
    public TableDataInfo findMonitorFundsAndProjectNames(InfoProjectMonitorFundsVo infoProjectMonitorFundsVo) {
        startPage();
        List<Map<String, Object>> list = infoProjectMonitorFundsService.findMonitorFundsAndProjectNames(infoProjectMonitorFundsVo);
        return getDataTable(list);
    }

}
